// 从 'cli-color' 模块中导入 clc，用于在终端中输出彩色文字
import clc from "cli-color";
//定义一个名为Logger的类
export class Logger {
  public static lastLogTime = Date.now();
  //定义一个静态方法log 该方法接收2个参数: message 和 context
  static log(message: string, context: string) {
    //获取当前日期和时间 并格式化为本地字符串
    const timestamp = new Date().toLocaleString();
    // 获取当前进程的 PID(进程标识符)
    const pid = process.pid;

    const currentTime = Date.now();
    const timeDiff = currentTime - this.lastLogTime;
    // 使用 clc.green() 将消息前缀设置为绿色，并输出到终端
    console.log(
      `${clc.green(["[Nest]"])} ${clc.green(pid.toString())} ${clc.green(
        "-"
      )}${clc.yellow(timestamp)}     ${clc.green("LOG")} ${clc.yellow(
        `[${context}]`
      )} ${clc.green(message)} +${clc.green(timeDiff)}${clc.green(`ms`)}`
    );
    this.lastLogTime = currentTime;
  }
}
